package com.example.slack.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.example.slack.controller.param.EventSubscribeParam;
import com.slack.api.bolt.App;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;

//@RequestMapping("")
//@RestController()
public class SlackAppController2{
    @Autowired
    private App app;

    @PostMapping("/slack/events2")
    public String aa(@RequestBody EventSubscribeParam param) {
        System.out.println();
        return param.getChallenge();
    }

    @PostMapping("/slack/events")
    public String aa(@RequestBody JSONObject event) {
        System.out.println(JSON.toJSONString(event));
        String result = "success";
        String eventType = event.getString("type");
        switch (eventType) {
            case "url_verification":
                EventSubscribeParam eventSubscribeParam = event.toJavaObject(EventSubscribeParam.class);
                result = eventSubscribeParam.getChallenge();
                break;
            case "event_callback":
                // 放入kafka，后续从AI获取答案并返回
                break;
        }
        return result;
    }

    /**
     * Interactivity & Shortcuts 重定向地址
     * @param param
     * @return
     */
    @PostMapping(value = "/slack/events3")
    public String events3(@RequestParam HashMap<String, Object> param) {
//        app.client().chatPostMessage()
        System.out.println(JSON.toJSONString(param));
        return "hello";
    }
}